package com.xiaoshuidi.cloud.module.member.controller.app.card;

import com.alibaba.fastjson.JSONObject;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.security.core.annotations.PreAuthenticated;
import com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils;
import com.xiaoshuidi.cloud.module.member.controller.app.card.vo.MemberUserBankCardForm;
import com.xiaoshuidi.cloud.module.member.controller.app.card.vo.MemberUserBankCardVo;
import com.xiaoshuidi.cloud.module.member.controller.app.card.vo.OcrBankCardVo;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.card.MemberUserBankCardService;
import com.xiaoshuidi.cloud.module.member.utils.CommonIdVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;


/**
 * @description 租客银行卡
 * @author Leo Li
 * @date 2023-05-19 17:20:47
 * @version generator
 */
@Tag(name = "租客APP - 租客银行卡")
@RestController
@RequestMapping(ApiConstants.NAME+"/bank-card")
public class MemberUserBankCardController {

	@Autowired
    MemberUserBankCardService service;
    
    @GetMapping("/list-member-bank-card")
    @Operation(summary ="租客银行卡列表")
    @PreAuthenticated
    public CommonResult<List<MemberUserBankCardVo>> listMemberBankCard() throws Exception {
		List<MemberUserBankCardVo> list = service.listMemberBankCardById(SecurityFrameworkUtils.getLoginUserId());
        return CommonResult.success(list);
    }

    @PostMapping("/bind-member-bank-card")
    @Operation(summary = "租客绑定银行卡")
    @PreAuthenticated
    public CommonResult<Boolean> bindMemberBankCard(@Valid @RequestBody MemberUserBankCardForm form){
        service.bindMemberBankCard(form);
        return CommonResult.success(Boolean.TRUE);
    }

    @PostMapping("/disable-member-bank-card")
    @Operation(summary = "租客删除银行卡")
    @PreAuthenticated
    public CommonResult<Boolean> disableMemberBankCard(@Valid @RequestBody CommonIdVo form){
        service.disableMemberBankCard(form.getId());
        return CommonResult.success(Boolean.TRUE);
    }

    @PostMapping("/ocr-bank-card")
    @Operation(summary = "识别银行卡")
    public CommonResult<OcrBankCardVo> ocrBankCard(@RequestParam("card") MultipartFile file) throws Exception {
        OcrBankCardVo json = service.orcBankCard(file);
        return CommonResult.success(json);
    }

}

